package com.huakai.springenv.service.impl.timeprofiler;

import com.huakai.springenv.aspect.profiler.DBTimeProfiler;
import com.huakai.springenv.utils.SleepUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
@Slf4j
public class TimeProfilerService {

    /**
     * 引入Spring代理过后的对象，否则无法被aop增强
     */
    @Resource
    private TimeProfilerService self;


    @DBTimeProfiler
    public void method() {
        SleepUtils.waitTime(200);
        log.info("{}#{} completed", getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
        self.method2();
    }

    @DBTimeProfiler
    public void method2() {
        SleepUtils.waitTime(400);
        log.info("{}#{} completed", getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
        self.method3();
    }

    @DBTimeProfiler
    public void method3() {
        SleepUtils.waitTime(600);
        log.info("{}#{} completed", getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
    }
}
